#include <boost/progress.hpp>
#include <boost/timer.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;

#define BOOST_ALLOW_DEPRECATED_HEADERS // disable pragma warning

void waist_time()
{
    // 模拟一个耗时操作
    for (int i = 0; i < 100000000 * 3; ++i)
        ;
}

void test_timer()
{
    boost::timer t;
    waist_time();
    // 获取并打印已用时间
    double elapsed = t.elapsed();
    std::cout << "Elapsed time: " << elapsed << " seconds." << std::endl;
}

void test_progress_timer()
{
    // 输出到标准输出流
    std::cout << "Timing to console:\n";
    {
        boost::progress_timer t(std::cout);
        waist_time();
    }

    // 输出到字符串流
    std::ostringstream oss;
    {
        boost::progress_timer t(oss);
        waist_time();
    }
    std::cout << "Timing to string stream: " << oss.str();

    // 输出到文件
    std::ofstream ofs("timing_output.txt");
    {
        boost::progress_timer t(ofs);
        waist_time();
    }
    ofs.close();
}

int main()
{
    test_progress_timer();
}